class Utils{
	
	constructor(){
		this.baseUrl = 'http://159.75.169.224:7300/pz'
	}
	
	getUserInfo(){
		uni.login({
			success: (res) => {
				this.request({
					url:'/auth/wxLogin',
					data:{
						'code':res.code
					},
					success:(response)=>{
						
					}
				})
			}
		})
	}
	request(option={
		showLoading:false
	}){
		// 判断url是否存在
		if(!option.url){
			return false;
		}
		if(option.showLoading){
			this.showLoading()
		}
		uni.request({
			url:(this.baseUrl + option.url),
			data:option.data ? option.data : {},
			header:option.header ? option.header : {},
			method:option.method ? option.method : 'GET',
			success: (response) => {
				uni.hideLoading()
				if(response.data.code != 10000){
					if(option.fail && typeof option.fail == 'function'){
						option.fail(response)
					}
				}else{
					if(option.success && typeof option.success == 'function'){
						option.success(response)
					}
				}
			},
			fail: (response) => {
				uni.hideLoading()
				console.log(response)
			}
		})
	}
	showLoading(){
		const isShowLoading = uni.getStorageSync('isShowLoading')
		if(isShowLoading){
			uni.hideLoading()
			uni.setStorageSync('isShowLoading', false)
		}
		uni.showLoading({
			title:'加载中...',
			complete:function(){
				uni.setStorageSync('isShowLoading', true)
			},
			fail:function() {
				uni.setStorageSync('isShowLoading', false)
			}
		})
	}
}

export default new Utils()